package de.chessgame.gamelogic;

import de.chessgame.gamelogic.piece.Fraction;
import de.chessgame.gamelogic.piece.Piece;
import de.chessgame.gamelogic.piece.Type;



public class InitialPosition {
	
	
	private static Type k = Type.KING;
	private static Type q = Type.QUEEN;
	private static Type r = Type.ROOK;
	private static Type n = Type.KNIGHT;
	private static Type i = Type.BISHOP;
	private static Type p = Type.PAWN;
	
	private static Fraction w = Fraction.WHITE;
	private static Fraction b = Fraction.BLACK;
	
	private static final int SIZE = 8;
	
	private static final Fraction[][] fractionAtStart = new Fraction[][] {
		
		//	a (0)	b (1)	c (2)	d (3)	e (4)	f (5)	g (6)	h (7)
		{	b,		b,		b,		b,		b,		b,		b,		b	},	// 8 (0)
		{	b,		b,		b,		b,		b,		b,		b,		b	},	// 7 (1)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 6 (2)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 5 (3)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 4 (4)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 3 (5)
		{	w,		w,		w,		w,		w,		w,		w,		w	},	// 2 (6)
		{	w,		w,		w,		w,		w,		w,		w,		w	}	// 1 (7)
	};
	
	private static final Type[][] typesAtStart = new Type[][] {
		
		//	a (0)	b (1)	c (2)	d (3)	e (4)	f (5)	g (6)	h (7)
		{	r,		n,		i,		q,		k,		i,		n,		r	},	// 8 (0)
		{	p,		p,		p,		p,		p,		p,		p,		p	},	// 7 (1)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 6 (2)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 5 (3)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 4 (4)
		{	null, 	null, 	null, 	null, 	null, 	null, 	null, 	null},	// 3 (5)
		{	p,		p,		p,		p,		p,		p,		p,		p	},	// 2 (6)
		{	r,		n,		i,		q,		k,		i,		n,		r	}	// 1 (7)
	
	};
	
	/**
	 * Generates an 8x8 Array, witch holds the initial positions of the pieces.
	 * @return
	 */
	public static Piece[][] generate() {
		Piece[][] initialPosition = new Piece[SIZE][SIZE];
		for (int i = 0; i < fractionAtStart.length && i < typesAtStart.length; i++) {
			for (int j = 0; j < fractionAtStart[i].length
					&& j < typesAtStart[i].length; j++) {

				if (typesAtStart[i][j] != null && fractionAtStart[i][j] != null) {
					initialPosition[i][j] = Piece.createPiece(typesAtStart[i][j], fractionAtStart[i][j]);
				} 
			}
		}
		return initialPosition;

	}
	
	public static Piece[][] getEmptyBoard() {
		return new Piece[SIZE][SIZE];
	}
	
}
